package com.zhyl.demo.controller;

import com.zhyl.demo.entity.Prescription;
import com.zhyl.demo.service.PrescriptionService;
import com.zhyl.demo.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yang3
 */
@RestController
@RequestMapping("/prescription")
public class PrescriptionController {
    private final PrescriptionService prescriptionService;
    @Autowired
    private PrescriptionController(PrescriptionService prescriptionService){
        this.prescriptionService = prescriptionService;
    }

    @RequestMapping("/addPrescription")
    public Result addPrescription(@RequestBody Prescription prescription)
    {
        if (prescription==null){
            return Result.error("参数错误");
        }
        Boolean aBoolean = prescriptionService.addPrescription(prescription);
        int prescriptionId = prescription.getId();
        if (aBoolean==true){
            return Result.success(prescriptionId);
        }else {
            return Result.error("生成失败");
        }
    }
}
